home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / os2 / octa209b.zip / octave-2.09 / DLFCN.ZIP / dlfcn / octave / MArray.h < prev    next >
C/C++ Source or Header  |  1997-08-20  |  4KB  |  124 lines

  1. // Template array classes with like-type math ops
  2. /*
  3.  
  4. Copyright (C) 1996 John W. Eaton
  5.  
  6. This file is part of Octave.
  7.  
  8. Octave is free software; you can redistribute it and/or modify it
  9. under the terms of the GNU General Public License as published by the
  10. Free Software Foundation; either version 2, or (at your option) any
  11. later version.
  12.  
  13. Octave is distributed in the hope that it will be useful, but WITHOUT
  14. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  15. FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  16. for more details.
  17.  
  18. You should have received a copy of the GNU General Public License
  19. along with Octave; see the file COPYING.  If not, write to the Free
  20. Software Foundation, 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  21.  
  22. */
  23.  
  24. #if defined (__GNUG__)
  25. #pragma interface
  26. #endif
  27.  
  28. #if !defined (octave_MArray_h)
  29. #define octave_MArray_h 1
  30.  
  31. #include "Array.h"
  32.  
  33. // One dimensional array with math ops.
  34.  
  35. template <class T>
  36. class MArray : public Array<T>
  37. {
  38. protected:
  39.  
  40.   MArray (T *d, int l) : Array<T> (d, l) { }
  41.  
  42. public:
  43.   
  44.   MArray (void) : Array<T> () { }
  45.   MArray (int n) : Array<T> (n) { }
  46.   MArray (int n, const T& val) : Array<T> (n, val) { }
  47. //  MArray (const Array<T>& a) : Array<T> (a) { }
  48.   MArray (const MArray<T>& a) : Array<T> (a) { }
  49.  
  50.   ~MArray (void) { }
  51.  
  52.   MArray<T>& operator = (const MArray<T>& a)
  53.     {
  54.       Array<T>::operator = (a);
  55.       return *this;
  56.     }
  57.  
  58.   // element by element MArray by scalar ops
  59.  
  60.   friend MArray<T>& operator += (MArray<T>& a, const T& s);
  61.   friend MArray<T>& operator -= (MArray<T>& a, const T& s);
  62.  
  63.   // element by element MArray by MArray ops
  64.  
  65.   friend MArray<T>& operator += (MArray<T>& a, const MArray<T>& b);
  66.   friend MArray<T>& operator -= (MArray<T>& a, const MArray<T>& b);
  67.  
  68.   // element by element MArray by scalar ops
  69.  
  70.   friend MArray<T> operator + (const MArray<T>& a, const T& s);
  71.   friend MArray<T> operator - (const MArray<T>& a, const T& s);
  72.   friend MArray<T> operator * (const MArray<T>& a, const T& s);
  73.   friend MArray<T> operator / (const MArray<T>& a, const T& s);
  74.  
  75.   // element by element scalar by MArray ops
  76.  
  77.   friend MArray<T> operator + (const T& s, const MArray<T>& a);
  78.   friend MArray<T> operator - (const T& s, const MArray<T>& a);
  79.   friend MArray<T> operator * (const T& s, const MArray<T>& a);
  80.   friend MArray<T> operator / (const T& s, const MArray<T>& a);
  81.  
  82.   // element by element MArray by MArray ops
  83.  
  84.   friend MArray<T> operator + (const MArray<T>& a, const MArray<T>& b);
  85.  
  86.   friend MArray<T> operator - (const MArray<T>& a, const MArray<T>& b);
  87.  
  88.   friend MArray<T> product (const MArray<T>& a, const MArray<T>& b);
  89.   friend MArray<T> quotient (const MArray<T>& a, const MArray<T>& b);
  90.  
  91.   friend MArray<T> operator - (const MArray<T>& a);
  92. };
  93.  
  94. extern void
  95. gripe_nonconformant (const char *op, int op1_len, int op2_len);
  96.  
  97.  
  98. #define INSTANTIATE_MARRAY_FRIENDS(T) \
  99.   template MArray<T>& operator += (MArray<T>& a, const T& s); \
  100.   template MArray<T>& operator -= (MArray<T>& a, const T& s); \
  101.   template MArray<T>& operator += (MArray<T>& a, const MArray<T>& b); \
  102.   template MArray<T>& operator -= (MArray<T>& a, const MArray<T>& b); \
  103.   template MArray<T> operator + (const MArray<T>& a, const T& s); \
  104.   template MArray<T> operator - (const MArray<T>& a, const T& s); \
  105.   template MArray<T> operator * (const MArray<T>& a, const T& s); \
  106.   template MArray<T> operator / (const MArray<T>& a, const T& s); \
  107.   template MArray<T> operator + (const T& s, const MArray<T>& a); \
  108.   template MArray<T> operator - (const T& s, const MArray<T>& a); \
  109.   template MArray<T> operator * (const T& s, const MArray<T>& a); \
  110.   template MArray<T> operator / (const T& s, const MArray<T>& a); \
  111.   template MArray<T> operator + (const MArray<T>& a, const MArray<T>& b); \
  112.   template MArray<T> operator - (const MArray<T>& a, const MArray<T>& b); \
  113.   template MArray<T> product (const MArray<T>& a, const MArray<T>& b); \
  114.   template MArray<T> quotient (const MArray<T>& a, const MArray<T>& b); \
  115.   template MArray<T> operator - (const MArray<T>& a);
  116.  
  117. #endif
  118.  
  119. /*
  120. ;;; Local Variables: ***
  121. ;;; mode: C++ ***
  122. ;;; End: ***
  123. */
  124.